﻿using Dapper.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using YouWei.Infrastructure.Entity;
using YouWei.Infrastructure.Models;
using YouWei.Infrastructure.Service;

namespace YouWei.Op.Controllers
{
    /// <summary>
    /// 微信用户
    /// </summary>
    public class WeChartUserController : BaseController
    {
        WeChartUserService wcuService = new WeChartUserService();

        // GET: WeChartUser
        public ActionResult Index()
        {
            ViewBag.OpenID = GetParam("openid");
            ViewBag.UnionID = GetParam("unionid");
            //ViewBag.GroupID = GetParam("groupid");
            return View();
        }

        /// <summary>
        /// 查询列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ContentResult List(WechatUserSearchModel model)
        {
            int pageIndex = GetPageIndex();
            int pageSize = GetPageSize();
            Page<WeChartUser> page = wcuService.Pages(pageIndex, pageSize, model);
            return ReturnResult(page);
        }

        /// <summary>
        /// 获取用户详情
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult Detail(int userId)
        {
            WeChartUser usr = wcuService.Single(userId);
            return View(usr);
        }

        /// <summary>
        /// 获取用户详情
        /// </summary>
        /// <param name="openid"></param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult DetailOpenID(string openid)
        {
            //如果unio
            WeChartUser usr = wcuService.GetByOpenID(openid);
            return PartialView(usr);
        }

    }
}